home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet 2002 February / Practical Internet February 2002.iso / pc / Software / Browsing / httrack-3.09e2.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-28  |  97.8 KB  |  2,862 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. // Ras
  12. #if USE_RAS 
  13. #include "RasLoad.h"
  14. #endif
  15.  
  16. #include <afxdisp.h>
  17. #include "ras.h"
  18.  
  19. //#include "ShellDoc.h"
  20. //#include "ShellView.h"
  21.  
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. // PATCH-->
  29. // PATCH-->
  30. #include "about.h"
  31. #include "infoend.h"
  32.  
  33. // flag de termination
  34. int termine=0;
  35. int termine_requested=0;
  36. int shell_terminated=0;
  37. int soft_term_requested=0;
  38. FILE* fp_debug=NULL;
  39.  
  40. #include "stdafx.h"
  41. #include "Shell.h"
  42. #include "process.h"
  43. //#include "ShellDoc.h"
  44. //#include "ShellView.h"
  45. //#include "essai.h"
  46. //#include "get.h"
  47. //#include "parameter.h"
  48. #include "htssystem.h"
  49. #include "Wid1.h"
  50. #include "trans.h"
  51. #include "InfoUrl.h"
  52. //#include "option.h"
  53. //#include "filter.h"
  54. //#include "wizard.h"
  55. //
  56. #include "maintab.h"
  57. //
  58. #include "MemRegister.h"
  59.  
  60. // LANG
  61. #include "newlang.h"
  62.  
  63.  
  64. // PATCH-->
  65. //#include "wizard2.h"
  66. //#include "WizLinks.h"
  67.  
  68. #include "inprogress.h"
  69.  
  70. #include "SYS\TIMEB.H"
  71.  
  72. // htswrap_add
  73. extern "C" {
  74. #include "htswrap.h"
  75. };
  76.  
  77. // --- --- --- --- Options --- --- --- ---
  78.  
  79. #define MAX_LEN_INPROGRESS 32
  80.  
  81. // lancement en multithread du shell ET de gethostbyname
  82. #define SHELL_MULTITHREAD 1
  83. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  84. // --- --- --- --- Options --- --- --- ---
  85. int INREDRAW_LOCKED=0;      // refresh graphique en cours
  86. int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  87. int HTTRACK_result=0;
  88. //
  89. CInfoUrl* _Cinprogress_inst=NULL;
  90.  
  91. extern HICON httrack_icon;
  92.  
  93. /* Main splitter frame */
  94. #include "DialogContainer.h"
  95. #include "splitter.h"
  96. extern CSplitterFrame* this_CSplitterFrame;
  97.  
  98. /* Main WizTab frame */
  99. #include "WizTab.h"
  100. extern CWizTab* this_CWizTab;
  101. /* Argh - pas de domodal dans des autres threads ?!?! */
  102. char WIZ_question[1000];
  103. char WIZ_reponse[1000];
  104.  
  105.  
  106. // Fonctionnement des THREADS:
  107. //
  108. // principal ---> robot & refresh data (thread 1)
  109. //           ---> refresh graphique    (thread 2)
  110. //           GO!> boucle gestion domodal() et boutons
  111. // arrΩt: principal demande l'arrΩt (termine_requested)
  112. //        thread1 active termine et que thread2 ait fini de refresher
  113. //        thread2 se termine
  114. //        thread1 retourne 0 α hts_loop
  115. //        le robot termine
  116. //        le thread1 active termine, termine le formulaire et se termine
  117. //        principal ayant quittΘ le formulaire affiche le message de fin
  118.  
  119.  
  120. // htslib.c
  121. extern "C" void qsec2str(char *st,TStamp t);
  122.  
  123. // construction index gΘnΘral
  124. // void Build_TopIndex();
  125.  
  126. void compute_options() ;
  127. char* connversion(char chaine[10000]);
  128. void lance(void);
  129. int check_continue(char* pathlog);
  130. int inprogress_refresh();
  131. //int inprogress_refresh_scan();
  132. void Write_profile(CString path,int load_path);
  133. void Read_profile(CString path,int load_path);
  134.  
  135.  
  136. // dΘja fait mais bon
  137. #define HTS_WIN 1
  138.  
  139. extern "C" {
  140. #include "htscore.h"
  141. }
  142.  
  143. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  144.  
  145. char LINE[32768];
  146. char OPTIONurl[32000];
  147. char OPTIONfilelist[HTS_URLMAXSIZE*2];
  148. char OPTIONproxy[500];
  149. char OPTIONport[100];
  150. char OPTIONdepth[20];
  151. char OPTIONextdepth[20];
  152. char OPTIONget[10];
  153. //char OPTIONlevel[10];
  154. char OPTIONwhere[8];
  155. char OPTIONmeth[8];
  156. char OPTIONmaxfile[100];
  157. char OPTIONmax[100];
  158. char OPTIONfrag[100];
  159. char OPTIONconn[100];
  160. char OPTIONtog[10];
  161. char OPTIONcache[8];
  162. char OPTIONrobots[8];
  163. char choixdeb[8];
  164. char build[256];
  165. char filtre[32];
  166. char OPTIONhtmlfirst[8];
  167. char OPTIONindex[8];
  168. char OPTIONindex2[8];
  169. char OPTIONdos[8];
  170. char OPTIONtime[20];
  171. char OPTIONrate[20];
  172. char OPTIONhostquit[20];
  173. char OPTIONuser[256];
  174. char OPTIONfooter[256];
  175. char OPTIONlog[8];
  176. char OPTIONtestall[8];
  177. char OPTIONparseall[8];
  178. char OPTIONlink[8];
  179. char OPTIONpath[1000];
  180. char OPTIONretry[16];
  181. char OPTIONerrpage[8];
  182. char OPTIONexternal[8];
  183. char OPTIONnopurge[8];
  184. char OPTIONhidepwd[8];
  185. char OPTIONhidequery[8];
  186. char OPTIONcookies[8];
  187. char OPTIONchecktype[8];
  188. char OPTIONparsejava[8];
  189. char OPTIONCache2[8];
  190. char OPTIONlogtype[8];
  191. char OPTIONnorecatch[8];
  192. char OPTIONtoler[8];
  193. char OPTIONupdhack[8];
  194. char OPTIONhttp10[8];
  195. //-->
  196. char OPTIONwaittime[32];
  197. char OPTIONmaxtime[32];
  198. char OPTIONmaxrate[32];
  199. char OPTIONmaxconn[32];
  200. char OPTIONmaxlinks[32];
  201. char OPTIONhh[32];
  202. char OPTIONmm[32];
  203. char OPTIONss[32];
  204. //
  205. char buff_filtres[8192];
  206. char buff_MIME[8192];
  207. // RAS
  208. char OPTION_RasString[256];
  209. RASDIALPARAMS OPTION_dial;
  210.  
  211. // Fichier tempo
  212. FILE* tmpf=NULL;
  213. MemRegister tmpm;
  214.  
  215. CNewProj* dialog0=NULL;
  216. Wid1* dialog1=NULL;
  217. Ctrans* dialog2=NULL;
  218. //Coption dialog3;
  219. //Cfilter diafiltre;
  220. /*
  221. wizard diawiz;
  222. wizard2 diawiz2;
  223. WizLinks diawiz3;
  224. */
  225. //
  226. CMainTab* maintab=NULL;
  227. CShellApp* CShellApp_app=NULL;
  228.  
  229. #include "infoend.h"
  230. extern Cinfoend* this_Cinfoend;
  231.  
  232.  
  233. // PATCH-->
  234. Cinprogress* inprogress=NULL;
  235.  
  236. // nbre de slides
  237. t_StatsBuffer StatsBuffer[NStatsBuffer];
  238. void* StatsBufferback=NULL;
  239. int StatsBufferback_max=0;
  240. InpInfo SInfo;
  241.  
  242. #if USE_RAS
  243. // Chargement des librairies RAS
  244. CDynamicRAS* LibRas=NULL;
  245. int LibRasUse=0;
  246. //
  247. int connected=0;
  248. int disconnect=0;
  249. HRASCONN conn = NULL;
  250. int has_started=0;
  251. char connected_err[1000]="";
  252. #endif
  253.  
  254. // pour message final
  255. extern char end_mirror_msg[8192];
  256. #include "winhttrack.h"
  257. extern CWinHTTrackApp* this_app;
  258.  
  259.  
  260. // PATCH-->
  261. // PATCH-->
  262. // FIN PATCH
  263.  
  264.  
  265. /////////////////////////////////////////////////////////////////////////////
  266. // CShellApp
  267.  
  268. /*
  269. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  270. //{{AFX_MSG_MAP(CShellApp)
  271. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  272. // NOTE - the ClassWizard will add and remove mapping macros here.
  273. //    DO NOT EDIT what you see in these blocks of generated code!
  274. //}}AFX_MSG_MAP
  275. // Standard file based document commands
  276. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  277. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  278. // Standard print setup command
  279. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  280. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  281. END_MESSAGE_MAP()
  282. */
  283.  
  284. /////////////////////////////////////////////////////////////////////////////
  285. // CShellApp construction
  286.  
  287. CShellApp::CShellApp()
  288. {
  289.   // TODO: add construction code here,
  290.   // Place all significant initialization in InitInstance
  291. }
  292.  
  293. /////////////////////////////////////////////////////////////////////////////
  294. // The one and only CShellApp object
  295.  
  296. //CShellApp theApp;
  297.  
  298. /////////////////////////////////////////////////////////////////////////////
  299. // CShellApp initialization
  300.  
  301. UINT RunBackMirror( LPVOID pP ) {
  302.   CShellApp_app->init_lance();
  303.   return 0;
  304. }
  305.  
  306. BOOL LaunchMirror() {
  307.   AfxBeginThread(RunBackMirror,NULL);
  308.   return 0;
  309. }
  310.  
  311. #if 0
  312. BOOL CShellApp::InitInstance()
  313. {
  314.   CShellApp_app=this;
  315.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  316.   
  317.   // Initialize OLE libraries
  318.   /*
  319.   if (!AfxOleInit())
  320.   {
  321.   AfxMessageBox(LANG(LANG_F1));
  322.   return FALSE;
  323.   }
  324.   AfxEnableControlContainer();
  325.   */
  326.   
  327.   // Fixer localisation dans la base de registre
  328.   //SetRegistryKey("WinHTTrack");
  329.   
  330.   // Standard initialization
  331.   // If you are not using these features and wish to reduce the size
  332.   //  of your final executable, you should remove from the following
  333.   //  the specific initialization routines you do not need.
  334.   /*
  335.   #ifdef _AFXDLL
  336.   Enable3dControls();            // Call this when using MFC in a shared DLL
  337.   #else
  338.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  339.   #endif
  340.   */
  341.   
  342.   // Register the application's document templates.  Document templates
  343.   //  serve as the connection between documents, frame windows and views.
  344.   
  345.   // Change the registry key under which our settings are stored.
  346.   // You should modify this string to be something appropriate
  347.   // such as the name of your company or organization.
  348.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  349.   
  350.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  351.   
  352.   // Register the application's document templates.  Document templates
  353.   //  serve as the connection between documents, frame windows and views.
  354.   
  355.   // Parse command line for standard shell commands, DDE, file open
  356.   /*CCommandLineInfo cmdInfo;
  357.   ParseCommandLine(cmdInfo);
  358.   */
  359.   
  360.   _Cinprogress_inst=NULL;
  361.   
  362.   LibRasUse=0;
  363.   
  364.   /*
  365.   #if USE_RAS
  366.   LibRas=new CDynamicRAS();
  367.   if (LibRas->IsRASLoaded()) 
  368.   LibRasUse=1;
  369.   else
  370.   LibRasUse=0;
  371.   #endif
  372.   */
  373.   
  374.   maintab = new CMainTab("WinHTTrack Website Copier");
  375.   
  376.   // PATCH-->
  377.   // ΘxΘcution..
  378.   init_lance();
  379.   
  380.   delete maintab;
  381.   maintab=NULL;
  382.   
  383.   // PATCH-->
  384.   /*
  385.   // Dispatch commands specified on the command line
  386.   if (!ProcessShellCommand(cmdInfo))
  387.         return FALSE;
  388.     
  389.       // The one and only window has been initialized, so show and update it.
  390.       m_pMainWnd->ShowWindow(SW_SHOW);
  391.       m_pMainWnd->UpdateWindow();
  392.   */  
  393.   
  394.   
  395.   return TRUE;
  396. }
  397. #endif
  398.  
  399. // PATCH-->
  400. // routines diverses
  401.  
  402. char* _SN(LLint n) {
  403.   static char str[256];
  404.   str[0]='\0';
  405.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  406.   return str;
  407. }
  408.  
  409. // t existe-t-il comme rΘpertoire?
  410. int dir_check(char* t) {
  411.   int dir;
  412.   FILE* fp=fopen(t,"rb");
  413.   dir=(errno==13);  // is directory
  414.   if (fp) fclose(fp);
  415.   return dir;
  416. }
  417.  
  418. void check_temp(char* t,char* s) {
  419.   if (strlen(s)==0)
  420.     if (dir_check(t))
  421.       strcpy(s,t);
  422. }
  423.  
  424.  
  425.  
  426. // PATCH-->
  427. // Routines gestion dials
  428. // PatchΘ pour 100% dials
  429.  
  430.  
  431. void CShellApp::init_lance() {
  432.   hts_init();
  433.   htswrap_add("check-link",httrackengine_check);
  434.   htswrap_add("init",httrackengine_init);
  435.   htswrap_add("free",httrackengine_uninit);
  436.   htswrap_add("start",httrackengine_start);
  437.   htswrap_add("end",httrackengine_end);
  438.   htswrap_add("check-html",httrackengine_htmlcheck);
  439.   htswrap_add("change-options",httrackengine_chopt);
  440.   htswrap_add("loop",httrackengine_loop);
  441.   htswrap_add("query",httrackengine_query);
  442.   htswrap_add("query2",httrackengine_query2);
  443.   htswrap_add("query3",httrackengine_query3);
  444.   htswrap_add("pause",httrackengine_pause);
  445.   
  446.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  447.   lance();             // Lancer miroir!
  448.   if (fp_debug) {
  449.     fprintf(fp_debug,"Building top index\r\n");
  450.     fflush(fp_debug);
  451.   }
  452.   Build_TopIndex();
  453. }
  454.  
  455. /* sauver profile */
  456. /* ask: demande confirmation, si cela vaut le coup */
  457. int Save_current_profile(int ask) {
  458.   CString winprofile;
  459.   if (ask) {
  460.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  461.       return IDNO;
  462.     int r;
  463.     char msg[256];
  464.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  465.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  466.       return r;
  467.   }
  468.   //
  469.   CWaitCursor wait;
  470.   
  471.   // sauver whtt
  472.   {
  473.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  474.     FILE* fp=fopen(st,"wb");
  475.     if (fp) fclose(fp);
  476.   }
  477.   
  478.   // sauver ini
  479.   winprofile=dialog0->GetPath();
  480.   if (winprofile.GetLength()>0)
  481.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  482.       winprofile+="\\";
  483.     winprofile+="hts-cache\\";
  484.     {
  485.       char tempo[HTS_URLMAXSIZE*2];
  486.       int i;
  487.       strcpy(tempo,winprofile);
  488.       for(i=0;i<(int)strlen(tempo);i++)
  489.         if (tempo[i]=='\\')
  490.           tempo[i]='/';              
  491.         structcheck(tempo);
  492.     }
  493.     
  494.     winprofile+="winprofile.ini";
  495.     Write_profile(winprofile,0);
  496.     
  497.     // marquer document comme "sauvΘ"
  498.     if (this_CSplitterFrame)
  499.       this_CSplitterFrame->SetSaved();
  500.     
  501.     return IDYES;
  502. }
  503.  
  504. // reprise possible?
  505. int check_continue(char* pathlog) {
  506.   char path_log[256];
  507.   strcpy(path_log,pathlog);
  508.   if (strlen(path_log)>0)
  509.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  510.       strcat(path_log,"/");
  511.     if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  512.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  513.       return 1;
  514.       //}
  515.     }
  516.     if ((fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  517.       return 1;
  518.     }
  519.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  520.     return 0;
  521. }
  522.  
  523.  
  524. void CShellApp::OptPannel() {
  525.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  526.   if (maintab->DoModal()==IDCANCEL) {
  527.     Read_profile("<mem>",0);      // restaurer
  528.   }
  529. }
  530.  
  531.  
  532. #define ADD_MIME_IN_COPT(A) \
  533.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  534.   strcat(buff_MIME,"--assume "); \
  535.   strcat(buff_MIME,maintab->m_option11.m_ext##A); \
  536.   strcat(buff_MIME,"="); \
  537.   strcat(buff_MIME,maintab->m_option11.m_mime##A); \
  538.   strcat(buff_MIME," "); \
  539.   } \
  540.   
  541. // parser maintab et calculer options
  542. void compute_options() { 
  543.   CWaitCursor wait;
  544.   
  545.   /* Effacer options */
  546.   LINE[0]
  547.     =OPTIONurl[0]
  548.     =OPTIONfilelist[0]
  549.     =OPTIONproxy[0]
  550.     =OPTIONport[0]
  551.     =OPTIONdepth[0]
  552.     =OPTIONextdepth[0]
  553.     =OPTIONget[0]
  554.     =OPTIONwhere[0]
  555.     =OPTIONmeth[0]
  556.     =OPTIONmaxfile[0]
  557.     =OPTIONmax[0]
  558.     =OPTIONfrag[0]
  559.     =OPTIONconn[0]
  560.     =OPTIONtog[0]
  561.     =OPTIONcache[0]
  562.     =OPTIONrobots[0]
  563.     =choixdeb[0]
  564.     =build[0]
  565.     =filtre[0]
  566.     =OPTIONindex[0]
  567.     =OPTIONindex2[0]
  568.     =OPTIONdos[0]
  569.     =OPTIONtime[0]
  570.     =OPTIONrate[0]
  571.     =OPTIONhostquit[0]
  572.     =OPTIONuser[0]
  573.     =OPTIONfooter[0]
  574.     =OPTIONlog[0]
  575.     =OPTIONtestall[0]
  576.     =OPTIONparseall[0]
  577.     =OPTIONlink[0]
  578.     =OPTIONpath[0]
  579.     =OPTIONretry[0]
  580.     =OPTIONerrpage[0]
  581.     =OPTIONexternal[0]
  582.     =OPTIONnopurge[0]
  583.     =OPTIONhidepwd[0]
  584.     =OPTIONhidequery[0]
  585.     =OPTIONcookies[0]
  586.     =OPTIONchecktype[0]
  587.     =OPTIONparsejava[0]
  588.     =OPTIONCache2[0]
  589.     =OPTIONlogtype[0]
  590.     =OPTIONnorecatch[0]
  591.     =OPTIONtoler[0]
  592.     =OPTIONupdhack[0]
  593.     =OPTIONhttp10[0]
  594.     =OPTIONwaittime[0]
  595.     =OPTIONmaxtime[0]
  596.     =OPTIONmaxrate[0]
  597.     =OPTIONmaxconn[0]
  598.     =OPTIONmaxlinks[0]
  599.     =OPTIONhh[0]
  600.     =OPTIONmm[0]
  601.     =OPTIONss[0]
  602.     =buff_filtres[0]
  603.     =buff_MIME[0]
  604.     =OPTION_RasString[0]
  605.     ='\0';
  606.   /* Effacer options */
  607.   
  608.   // Mode de miroir
  609.   switch(dialog1->m_todo) {
  610.   case CB_ERR: case 0:
  611.     strcpy(choixdeb,"w");
  612.     break;
  613.   case 1:
  614.     strcpy(choixdeb,"W");
  615.     break;
  616.   case 2:
  617.     strcpy(choixdeb,"g");
  618.     break;
  619.   case 3:
  620.     strcpy(choixdeb,"Y");
  621.     break;
  622.   case 4:
  623.     strcpy(choixdeb,"!");
  624.     break;
  625.   default:
  626.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  627.       strcpy(choixdeb,"i");    // reprise
  628.     else
  629.       strcpy(choixdeb,"/");    // reprise cache prioritaire
  630.     break;
  631.   }
  632.   
  633.   // URLS
  634.   char trans[50000];
  635.   strcpy(trans,"");
  636.   strncat(trans,dialog1->m_urls,30000);
  637.   strcpy(OPTIONurl,connversion(trans));
  638.   // --- formation du path
  639.   strcpy(OPTIONpath,"\""); strcat(OPTIONpath,dialog0->GetPath0()); strcat(OPTIONpath,"\"");
  640.   strcat(OPTIONpath,",");
  641.   strcat(OPTIONpath,"\""); strcat(OPTIONpath,dialog0->GetPath0()); strcat(OPTIONpath,"\"");
  642.   
  643.   // filelist
  644.   {
  645.     CString st=dialog1->m_filelist;
  646.     st.TrimLeft();
  647.     st.TrimRight();
  648.     strcpy(OPTIONfilelist,st);
  649.   }
  650.   
  651.   // stocker Θtat et hh/mm/ss
  652.   strcpy(OPTIONhh,dialog2->m_hh);
  653.   strcpy(OPTIONmm,dialog2->m_mm);
  654.   strcpy(OPTIONss,dialog2->m_ss);
  655.   if (strlen(OPTIONhh)) {    // heure
  656.     int x,y,z;
  657.     sscanf(OPTIONhh,"%d",&x);
  658.     x=min(max(x,0),23);
  659.     sprintf(OPTIONhh,"%d",x);
  660.     //
  661.     sscanf(OPTIONmm,"%d",&y);
  662.     y=min(max(y,0),59);
  663.     sprintf(OPTIONmm,"%d",y);
  664.     //
  665.     sscanf(OPTIONss,"%d",&z);
  666.     z=min(max(z,0),59);
  667.     sprintf(OPTIONss,"%d",z);
  668.     //
  669.     strcpy(OPTIONwaittime,"");
  670.     {
  671.       char str[32];
  672.       strcpy(OPTIONwaittime,"#u");
  673.       sprintf(str,"%d",x*3600+y*60+z);
  674.       strcat(OPTIONwaittime,str);
  675.     }
  676.   }
  677.   strcpy(OPTION_RasString,dialog2->RasString);
  678.   OPTION_dial=dialog2->dial;
  679.   
  680.   if (choixdeb[0]=='/') {
  681.     strcpy(OPTIONcache,"C1");      // cache prio
  682.   } else {
  683.     if(!maintab->m_option3.m_cache) 
  684.       strcpy(OPTIONcache,"C0"); 
  685.     else 
  686.       strcpy(OPTIONcache,"C2");     // cache non prio 
  687.     //OPTIONcache[0]='\0'; 
  688.   }
  689.   
  690.   // ne pas recharger fichiers dΘja pris mais effacΘs
  691.   if(maintab->m_option9.m_norecatch) strcpy(OPTIONnorecatch,"%n"); else strcpy(OPTIONnorecatch,"");
  692.   
  693.   // proxy
  694.   strcpy(OPTIONproxy,maintab->m_option10.m_proxy);
  695.   strcpy(OPTIONport,maintab->m_option10.m_port);
  696.   
  697.   //depth
  698.   strcpy(OPTIONdepth,maintab->m_option5.m_depth);
  699.   strcpy(OPTIONextdepth,maintab->m_option5.m_depth2);
  700.   
  701.   if(!maintab->m_option9.m_index) strcpy(OPTIONindex,"I0"); else OPTIONindex[0]='\0'; 
  702.   if(!maintab->m_option9.m_index2) strcpy(OPTIONindex2,"%I0"); else strcpy(OPTIONindex2,"%I"); 
  703.   if(maintab->m_option2.m_dos) strcpy(OPTIONdos,"L0"); else OPTIONdos[0]='\0'; 
  704.   if(maintab->m_option1.m_testall) strcpy(OPTIONtestall,"t"); else OPTIONtestall[0]='\0'; 
  705.   if(maintab->m_option1.m_parseall) strcpy(OPTIONparseall,"%P"); else strcpy(OPTIONparseall,"%P0"); 
  706.   if(maintab->m_option1.m_link) strcpy(OPTIONlink,"n"); else OPTIONlink[0]='\0'; 
  707.   if(maintab->m_option1.m_htmlfirst) strcpy(OPTIONhtmlfirst,"p7"); else strcpy(OPTIONhtmlfirst,""); 
  708.   if(maintab->m_option2.m_errpage) strcpy(OPTIONerrpage,"o0"); else OPTIONerrpage[0]='\0'; 
  709.   if(maintab->m_option2.m_external) strcpy(OPTIONexternal,"x"); else OPTIONexternal[0]='\0'; 
  710.   if(maintab->m_option2.m_nopurge) strcpy(OPTIONnopurge,"X0"); else OPTIONnopurge[0]='\0'; 
  711.   if(maintab->m_option2.m_hidepwd) strcpy(OPTIONhidepwd,"%x"); else OPTIONhidepwd[0]='\0'; 
  712.   if(maintab->m_option2.m_hidequery) strcpy(OPTIONhidequery,"%q0"); else OPTIONhidequery[0]='\0'; 
  713.   
  714.   OPTIONrobots[0]='\0';
  715.   if(maintab->m_option8.m_robots==0) strcpy(OPTIONrobots,"s0"); 
  716.   else if(maintab->m_option8.m_robots==1) strcpy(OPTIONrobots,"s1"); 
  717.   else if(maintab->m_option8.m_robots==2) strcpy(OPTIONrobots,"s2"); 
  718.   
  719.   // cookies,checktype,parsejava
  720.   if(maintab->m_option8.m_cookies==0) strcpy(OPTIONcookies,"b0"); // else strcpy(OPTIONcookies,"b1");
  721.   if (maintab->m_option8.m_checktype>=0)
  722.     sprintf(OPTIONchecktype,"u%d",maintab->m_option8.m_checktype);
  723.   if(maintab->m_option8.m_parsejava==0) strcpy(OPTIONparsejava,"j0"); // else strcpy(OPTIONcookies,"j1");
  724.   if (maintab->m_option8.m_http10) strcpy(OPTIONhttp10,"%h");   // HTTP/1.0 notamment
  725.   if (maintab->m_option8.m_toler)  strcpy(OPTIONtoler,"%B");    // tolerent
  726.   if (maintab->m_option8.m_updhack)  strcpy(OPTIONupdhack,"%s");    // update hack
  727.   
  728.   // store all in cache,logtype
  729.   if(maintab->m_option9.m_Cache2!=0) strcpy(OPTIONCache2,"k");
  730.   if(maintab->m_option9.m_logtype==1) strcpy(OPTIONlogtype,"z");
  731.   else if(maintab->m_option9.m_logtype==2) strcpy(OPTIONlogtype,"Z");
  732.   if (maintab->m_option3.m_windebug) strcat(OPTIONlogtype,"%H");      // debug headers
  733.   
  734.   strcpy(build,"");
  735.   if      (maintab->m_option2.m_build==0) strcpy(build,"N0");
  736.   else if (maintab->m_option2.m_build==1) strcpy(build,"N1");
  737.   else if (maintab->m_option2.m_build==2) strcpy(build,"N2");
  738.   else if (maintab->m_option2.m_build==3) strcpy(build,"N3");
  739.   else if (maintab->m_option2.m_build==4) strcpy(build,"N4");
  740.   else if (maintab->m_option2.m_build==5) strcpy(build,"N5");
  741.   else if (maintab->m_option2.m_build==6) strcpy(build,"N100");
  742.   else if (maintab->m_option2.m_build==7) strcpy(build,"N101");
  743.   else if (maintab->m_option2.m_build==8) strcpy(build,"N102");
  744.   else if (maintab->m_option2.m_build==9) strcpy(build,"N103");
  745.   else if (maintab->m_option2.m_build==10) strcpy(build,"N104");
  746.   else if (maintab->m_option2.m_build==11) strcpy(build,"N105");
  747.   else if (maintab->m_option2.m_build==12) strcpy(build,"N99");
  748.   else if (maintab->m_option2.m_build==13) strcpy(build,"N199");
  749.   else if (maintab->m_option2.m_build==14) {
  750.     strcpy(build,"-N \"");
  751.     strcat(build,maintab->m_option2.Bopt.m_BuildString);
  752.     strcat(build,"\"");
  753.   }
  754.   
  755.   strcpy(filtre,"");
  756.   if      (maintab->m_option3.m_filter==0) strcpy(filtre,"p0");
  757.   else if (maintab->m_option3.m_filter==1) strcpy(filtre,"p1");
  758.   else if (maintab->m_option3.m_filter==2) strcpy(filtre,"p2");
  759.   else if (maintab->m_option3.m_filter==3) {    /* default */
  760.     if(!maintab->m_option1.m_htmlfirst) strcpy(filtre,"p3");
  761.   }
  762.   else if (maintab->m_option3.m_filter==4) strcpy(filtre,"p7");
  763.   //
  764.   if      (maintab->m_option3.m_travel==0) strcat(filtre,"S");
  765.   else if (maintab->m_option3.m_travel==1) strcat(filtre,"D");
  766.   else if (maintab->m_option3.m_travel==2) strcat(filtre,"U");
  767.   else if (maintab->m_option3.m_travel==3) strcat(filtre,"B");
  768.   //
  769.   if      (maintab->m_option3.m_travel2==0) strcat(filtre,"a");
  770.   else if (maintab->m_option3.m_travel2==1) strcat(filtre,"d");
  771.   else if (maintab->m_option3.m_travel2==2) strcat(filtre,"l");
  772.   else if (maintab->m_option3.m_travel2==3) strcat(filtre,"e");
  773.   
  774.   if (maintab->m_option9.m_logf) strcpy(OPTIONlog,"f2"); else strcpy(OPTIONlog,"Q"); 
  775.   
  776.   if(maintab->m_option5.m_sizemax!=""){
  777.     strcpy(OPTIONmax,"M");
  778.     strcat(OPTIONmax,maintab->m_option5.m_sizemax);
  779.   } else strcpy(OPTIONmax,"");
  780.   
  781.   if(maintab->m_option5.m_pausebytes!=""){
  782.     strcpy(OPTIONfrag,"G");
  783.     strcat(OPTIONfrag,maintab->m_option5.m_pausebytes);
  784.   } else strcpy(OPTIONfrag,"");
  785.   
  786.   
  787.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  788.     strcpy(OPTIONmaxfile,"m");
  789.     if(maintab->m_option5.m_othermax!="") strcat(OPTIONmaxfile,maintab->m_option5.m_othermax);
  790.     else strcat(OPTIONmaxfile,"0");
  791.     if(maintab->m_option5.m_maxhtml!="") {strcat(OPTIONmaxfile,",");strcat(OPTIONmaxfile,maintab->m_option5.m_maxhtml);}
  792.     else {strcat(OPTIONmaxfile,",");strcat(OPTIONmaxfile,"0");}
  793.   } else strcpy(OPTIONmaxfile,"");
  794.   
  795.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  796.     strcpy(OPTIONconn,"c");
  797.     strcat(OPTIONconn,maintab->m_option4.m_connexion);
  798.   } else strcpy(OPTIONconn,"");
  799.   
  800.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  801.     strcpy(OPTIONtime,"T");
  802.     strcat(OPTIONtime,maintab->m_option4.m_timeout);
  803.   } else strcpy(OPTIONtime,"");
  804.   
  805.   // quitter host si timeout ou rate out
  806.   strcpy(OPTIONhostquit,"");
  807.   {
  808.     int a=0;
  809.     if (maintab->m_option4.m_remt)
  810.       a+=1;
  811.     if (maintab->m_option4.m_rems)
  812.       a+=2;
  813.     sprintf(OPTIONhostquit,"H%d",a);
  814.   }
  815.   
  816.   //--> max time
  817.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  818.     strcpy(OPTIONmaxtime,"E");
  819.     strcat(OPTIONmaxtime,maintab->m_option5.m_maxtime);
  820.   } else strcpy(OPTIONmaxtime,"");
  821.   
  822.   //--> max rate
  823.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  824.     strcpy(OPTIONmaxrate,"A");
  825.     strcat(OPTIONmaxrate,maintab->m_option5.m_maxrate);
  826.   } else strcpy(OPTIONmaxrate,"");
  827.   
  828.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  829.     strcpy(OPTIONmaxconn,"%c");
  830.     strcat(OPTIONmaxconn,maintab->m_option5.m_maxconn);
  831.   } else strcpy(OPTIONmaxconn,"");
  832.   
  833.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  834.     strcpy(OPTIONmaxlinks,"#L");
  835.     strcat(OPTIONmaxlinks,maintab->m_option5.m_maxlinks);
  836.   } else strcpy(OPTIONmaxlinks,"");
  837.   
  838.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  839.     strcpy(OPTIONrate,"J");
  840.     strcat(OPTIONrate,maintab->m_option4.m_rate);
  841.   } else strcpy(OPTIONrate,"");
  842.   
  843.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  844.     strcpy(OPTIONuser,"\"");
  845.     strcat(OPTIONuser,maintab->m_option6.m_user);
  846.     strcat(OPTIONuser,"\"");
  847.   } else strcpy(OPTIONuser,"");
  848.   
  849.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  850.     strcpy(OPTIONfooter,"\"");
  851.     strcat(OPTIONfooter,maintab->m_option6.m_footer);
  852.     strcat(OPTIONfooter,"\"");
  853.   } else strcpy(OPTIONfooter,"");
  854.   
  855.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  856.     strcpy(OPTIONretry,"R");
  857.     strcat(OPTIONretry,maintab->m_option4.m_retry);
  858.   } else strcpy(OPTIONretry,"");
  859.   
  860.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  861.     strcpy(buff_filtres,maintab->m_option7.m_url2);
  862.   } else strcpy(buff_filtres,"");
  863.   
  864.   
  865.   // MIME
  866.   buff_MIME[0]='\0';
  867.   ADD_MIME_IN_COPT(1)
  868.     ADD_MIME_IN_COPT(2)
  869.     ADD_MIME_IN_COPT(3)
  870.     ADD_MIME_IN_COPT(4)
  871.     ADD_MIME_IN_COPT(5)
  872.     ADD_MIME_IN_COPT(6)
  873.     ADD_MIME_IN_COPT(7)
  874.     ADD_MIME_IN_COPT(8)
  875.     
  876.     /* autres options: RAS */
  877.     if (dialog2->m_rasdisc)
  878.       disconnect=1;     /* dΘconnexion α la fin */
  879.     else
  880.       disconnect=0;
  881. }
  882.  
  883. // Les routines α dΘfinir:
  884. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelΘ par le wizard
  885.   return -1;
  886. }
  887. void __cdecl httrackengine_init() {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  888. #if USE_RAS
  889.   has_started=0;
  890. #endif
  891.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  892.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  893. }
  894. void __cdecl httrackengine_uninit() {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  895. #if USE_RAS
  896.   if (LibRasUse) {        /* librairie RAS chargΘe */
  897.     if (disconnect) {     /* on doit dΘconnecter */
  898.       if (connected) {    /* on a initiΘ une connexion */
  899.         if (conn)
  900.           LibRas->RasHangUp(conn);
  901.       } else {            /* tout dΘconnecter */
  902.         // On coupe tout (non, pas bourrin)
  903.         DWORD size;
  904.         RASCONN* adr;
  905.         int count=256;
  906.         size = sizeof(RASCONN)*(count+2);
  907.         adr = (RASCONN*) (char*) calloc(size,1);
  908.         if (adr) {
  909.           DWORD ent;
  910.           int i;
  911.           for(i=0;i<count;i++) {
  912.             adr[i].dwSize=sizeof(RASCONN);
  913.             strcpy(adr[i].szEntryName,"");
  914.           }
  915.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  916.             for(i=0;i<(int)ent;i++) {
  917.               LibRas->RasHangUp(adr[i].hrasconn);
  918.             }
  919.           }
  920.           free(adr);
  921.         }
  922.         
  923.       }
  924.     }
  925.   }
  926. #endif
  927. }
  928. int __cdecl httrackengine_start(void* dummy) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  929. #if USE_RAS
  930.   // connexion RAS
  931.   has_started=1;    // dΘmarrage
  932.   connected=0;
  933.   conn = NULL;
  934.   bzero((char*) &(SInfo), sizeof(SInfo));
  935.   if (LibRasUse) {
  936.     if (strlen(OPTION_RasString)>0) {    // sΘlection provider
  937.       if (!LibRas->RasDial(NULL,NULL,&OPTION_dial,NULL,NULL,&conn)) {
  938.         RASCONNSTATUS status;
  939.         do {
  940.           status.dwSize = sizeof(status);
  941.           LibRas->RasGetConnectStatus(conn,&status);
  942.           switch(status.rasconnstate) {
  943.           case RASCS_Connected : 
  944.             connected=1;
  945.             break;
  946.           case RASCS_Disconnected :
  947.             strcpy(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  948.             connected=-1;
  949.             break;
  950.           }
  951.         } while(connected==0);
  952.       } else {
  953.         strcpy(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  954.         connected=-1;
  955.         //termine=1;
  956.       }
  957.     }
  958.     //
  959.     if (connected != -1)  // si pas d'erreur RAS
  960.       return 1;
  961.     else
  962.       return 0;
  963.   } else
  964.     return 1;
  965. #else
  966.   return 1;
  967. #endif
  968. }
  969. int  httrackengine_end() {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  970.   if (_Cinprogress_inst) {
  971.     _Cinprogress_inst->EndDialog(IDOK);
  972.     _Cinprogress_inst=NULL;
  973.   }
  974.   return 1;
  975. }
  976. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  977.   return 1;
  978. }
  979. int __cdecl httrackengine_chopt(void* opt) {
  980.   return 1;
  981. }
  982.  
  983. // Le routine la plus utile sans doute: elle refresh les tableaux
  984. // C'est la 2e routine en thread qui assure le refresh graphique
  985. // (plus efficace)
  986. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  987. int __cdecl httrackengine_loop(
  988.                                void* _back,int back_max,int back_index,
  989.                                int lien_n,int lien_tot,
  990.                                int stat_time,
  991.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  992.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  993.   int stat_written=-1;
  994.   int stat_updated=-1;
  995.   int stat_errors=-1;
  996.   int nbk=-1;
  997.   LLint nb=-1;
  998.   int stat_nsocket=-1;
  999.   LLint stat_bytes=-1;
  1000.   LLint stat_bytes_recv=-1;
  1001.   int irate=-1;
  1002.   
  1003.   if (stats) {
  1004.     stat_written=stats->stat_files;
  1005.     stat_updated=stats->stat_updated_files;
  1006.     stat_errors=stats->stat_errors;
  1007.     nbk=stats->nbk;
  1008.     stat_nsocket=stats->stat_nsocket;
  1009.     irate=(int)stats->rate;
  1010.     nb=stats->nb;
  1011.     stat_bytes=stats->nb;
  1012.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1013.   }
  1014.   
  1015. #if !SHELL_MULTITHREAD
  1016.   static TStamp last_time;
  1017. #endif
  1018.   int rate;
  1019.   // casts
  1020.   lien_back* back=(lien_back*) _back;
  1021.   //  static int ft=-1;
  1022.   
  1023.   if (back_max == 0) {
  1024. #if !SHELL_MULTITHREAD
  1025.     last_time=0;
  1026. #endif
  1027.     // en cas de manque de time
  1028.     SInfo.stat_timestart=time_local();
  1029.     return 1;
  1030.   }
  1031.   
  1032.   if ((termine) || (termine_requested)) {
  1033.     SInfo.refresh=0;      // pas de refresh
  1034.     while(INREDRAW_LOCKED) Sleep(10);    // attendre refresh
  1035.     termine_requested=1;
  1036.     return 0;
  1037.   }
  1038.   
  1039.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1040.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1041.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1042.   
  1043. #if SHELL_MULTITHREAD 
  1044.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1045.   if (SInfo.ask_refresh) {
  1046. #else
  1047.     TStamp tl=0;
  1048.     {
  1049.       time_t tt;
  1050.       struct tm* A;
  1051.       tt=time(NULL);
  1052.       A=localtime(&tt);
  1053.       tl+=A->tm_sec;
  1054.       tl+=A->tm_min*60;
  1055.       tl+=A->tm_hour*60*60;
  1056.       //tl+=A->tm_yday*60*60*24;
  1057.       //tl+=A->tm_year*60*60*24*365;
  1058.       
  1059.       tl*=1000;  // en ms
  1060.       
  1061.       struct _timeb timebuffer;
  1062.       char *timeline;
  1063.       _ftime( &timebuffer );
  1064.       timeline = ctime( & ( timebuffer.time ) );
  1065.       
  1066.       tl+=timebuffer.millitm;    // + ms
  1067.     }
  1068.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1069.       last_time=tl;
  1070. #endif
  1071.       INFILLMEM_LOCKED=1;    // locker interface
  1072.       // OPTI int rate;
  1073.       SInfo.ask_refresh=0;
  1074.       
  1075.       // pour Θviter temps cpu consommΘ trop grand
  1076.       // Sleep(10);
  1077.       
  1078.       // initialiser ft
  1079.       if ((stat_nsocket==-1)) {
  1080.         if (SInfo.ft==-1) {
  1081.           SInfo.ft=stat_time;
  1082.         }
  1083.       }
  1084.       
  1085. #if !SHELL_MULTITHREAD
  1086.       //
  1087.       MSG msg;  
  1088.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1089.         switch (msg.message) {
  1090.         case WM_COMMAND:        
  1091.           switch(msg.wParam) { 
  1092.           case ID_APP_ABOUT: {
  1093.             Cabout about;
  1094.             about.DoModal();                                    }
  1095.             break;
  1096.           case ID_APP_EXIT: case WM_CLOSE :
  1097.             termine_requested=1;
  1098.             break;
  1099.           case  WM_DESTROY: case WM_NCDESTROY: 
  1100.             termine_requested=1;
  1101.             break;
  1102.           }
  1103.           break;        
  1104.           default:
  1105.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1106.             break;
  1107.         }
  1108.       }
  1109.       //
  1110. #endif
  1111.       
  1112.       // calculer heure si ce n'est dΘja fait
  1113.       if (stat_time<0)
  1114.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1115.       
  1116.       // calculer transfer rate
  1117.       if ((stat_time>0) && (stat_bytes_recv>0))
  1118.         rate=(int)(stat_bytes_recv/stat_time);
  1119.       else
  1120.         rate=0;    // pas d'infos
  1121.       
  1122.       // stocker infos: octets transfΘrΘs, temps, etc.
  1123.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1124.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1125.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1126.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1127.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1128.       if (rate>0)  SInfo.rate=rate;                // rate
  1129.       if (irate>=0) SInfo.irate=irate;             // irate
  1130.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1131.       if (SInfo.stat_back>=0) SInfo.stat_back=nbk;
  1132.       
  1133.       // back: tableau de back_max ΘlΘments de cache
  1134.       // back_max: nombre d'ΘlΘments ^^^^
  1135.       // lien_tot: nombre total de liens traitΘs pour le moment
  1136.       // stat_bytes: octets sauvegardΘs
  1137.       // stat_bytes_recv: octets tΘlΘchargΘs
  1138.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1139.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1140.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1141.       
  1142.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1143.       
  1144.       // parcourir registre des liens
  1145.       if (back_index>=0) {  // seulement si index passΘ
  1146.         int j,k;
  1147.         int index=0;
  1148.         int ok=0;         // idem
  1149.         int l;            // idem
  1150.         int M=32;         // idem
  1151.         
  1152.         StatsBufferback=(void*) back;
  1153.         StatsBufferback_max=back_max;
  1154.         {
  1155.           int i;
  1156.           for(i=0;i<NStatsBuffer;i++) {
  1157.             strcpy(StatsBuffer[i].etat,"");
  1158.             strcpy(StatsBuffer[i].nom,"");
  1159.             strcpy(StatsBuffer[i].fichier,"");
  1160.             strcpy(StatsBuffer[i].url_sav,"");
  1161.             StatsBuffer[i].back=NULL;
  1162.             StatsBuffer[i].size=0;
  1163.             StatsBuffer[i].sizetot=0;
  1164.           }
  1165.         }
  1166.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1167.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1168.             int _i;
  1169.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1170.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1171.               if (back[i].status>=0) {     // signifie "lien actif"
  1172.                 // int ok=0;  // OPTI
  1173.                 ok=0;
  1174.                 switch(j) {
  1175.                 case 0:     // prioritaire
  1176.                   if ((back[i].status>0) && (back[i].status<99)) {
  1177.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1178.                   }
  1179.                   break;
  1180.                 case 1:
  1181.                   if (back[i].status==99) {
  1182.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1183.                   }
  1184.                   else if (back[i].status==100) {
  1185.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1186.                   }
  1187.                   else if (back[i].status==101) {
  1188.                     strcpy(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1189.                   }
  1190.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1191.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1192.                   }
  1193.                   break;
  1194.                 default:
  1195.                   if (back[i].status==0) {  // prΩt
  1196.                     if ((back[i].r.statuscode==200)) {
  1197.                       strcpy(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1198.                     }
  1199.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1200.                       char tempo[256]; tempo[0]='\0';
  1201.                       infostatuscode(tempo,back[i].r.statuscode);
  1202.                       strcpy(StatsBuffer[index].etat,tempo); ok=1;
  1203.                     }
  1204.                     else {
  1205.                       strcpy(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1206.                     }
  1207.                   }
  1208.                   break;
  1209.                 }
  1210.                 
  1211.                 if (ok) {
  1212.                   // OPTI int l;
  1213.                   // OPTI int M=32;     // longueur
  1214.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1215.                   //
  1216.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1217.                   //
  1218.                   s[0]='\0';
  1219.                   strcpy(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1220.                   if (strcmp(back[i].url_adr,"file://"))
  1221.                     strcat(s,back[i].url_adr);
  1222.                   else
  1223.                     strcat(s,"localhost");
  1224.                   if (back[i].url_fil[0]!='/')
  1225.                     strcat(s,"/");
  1226.                   strcat(s,back[i].url_fil);
  1227.                   
  1228.                   StatsBuffer[index].fichier[0]='\0';
  1229.                   {
  1230.                     char* a=strrchr(s,'/');
  1231.                     if (a) {
  1232.                       strncat(StatsBuffer[index].fichier,a,200);
  1233.                       *a='\0';
  1234.                     }
  1235.                   }
  1236.                   
  1237.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1238.                     strcpy(StatsBuffer[index].nom,s);
  1239.                   else {
  1240.                     // couper
  1241.                     StatsBuffer[index].nom[0]='\0';
  1242.                     strncat(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1243.                     strcat(StatsBuffer[index].nom,"...");
  1244.                     strcat(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1245.                   }
  1246.                   
  1247.                   //if (back[i].url_fil[0]!='/') printf("/");
  1248.                   
  1249.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1250.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1251.                     StatsBuffer[index].size=back[i].r.size;
  1252.                   } else {  // pas de taille prΘdΘfinie
  1253.                     if (back[i].status==0) {  // prΩt
  1254.                       StatsBuffer[index].sizetot=back[i].r.size;
  1255.                       StatsBuffer[index].size=back[i].r.size;
  1256.                     } else {
  1257.                       StatsBuffer[index].sizetot=8192;
  1258.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1259.                     }
  1260.                   }
  1261.                   index++;
  1262.                 }
  1263.               }
  1264.             }
  1265.           }
  1266.         }
  1267.     }
  1268.     
  1269. #if SHELL_MULTITHREAD
  1270.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1271. #else
  1272.     inprogress_refresh();  // tout de suite (non multithread)
  1273. #endif
  1274.     INFILLMEM_LOCKED=0;    // dΘlocker interface
  1275.   }
  1276.   return (termine==0);
  1277. }
  1278.  
  1279. int inprogress_refresh() {
  1280.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1281.     if (SInfo.refresh) {
  1282.       INREDRAW_LOCKED=1;
  1283.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1284.       int icn;
  1285.       icn=inprogress->IsIconic();
  1286.       CString lnk;
  1287.       if (SInfo.stat_back)
  1288.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1289.       else
  1290.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1291.       if (!icn) {
  1292.         int parsing=0;
  1293.         if (!hts_setpause(-1)) {
  1294.           if (!(parsing=hts_is_parsing(-1)))
  1295.             inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1296.           else {
  1297.             switch(hts_is_testing()) {
  1298.             case 0:
  1299.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1300.               break;
  1301.             case 1:
  1302.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1303.               break;
  1304.             case 2:
  1305.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11b)); 
  1306.               break;
  1307.             }
  1308.           }
  1309.         } else
  1310.           inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1311.         
  1312.         if (SInfo.stat_time>0) {
  1313.           char s[256];
  1314.           qsec2str(s,(TStamp) SInfo.stat_time);
  1315.           inprogress->SetDlgItemText(IDC_i1 ,s);  // time
  1316.         } else
  1317.           inprogress->SetDlgItemText(IDC_i1 , _SN(SInfo.stat_time) );  // time
  1318.         inprogress->SetDlgItemText(IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1319.         inprogress->SetDlgItemText(IDC_i2 , lnk);  // scanned
  1320.         if (SInfo.stat_nsocket>0)
  1321.           inprogress->SetDlgItemText(IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1322.         else
  1323.           inprogress->SetDlgItemText(IDC_i3 , "none" );  // wait
  1324.         
  1325.         CString st;
  1326.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1327.         inprogress->SetDlgItemText(IDC_i4 , st );  // rate
  1328.         
  1329.         inprogress->SetDlgItemText(IDC_i5 , _SN(SInfo.stat_errors) );
  1330.         inprogress->SetDlgItemText(IDC_i6 , _SN(SInfo.stat_written) );
  1331.         {
  1332.           char tempo[256];
  1333.           int pc=0;
  1334.           if (SInfo.stat_written)
  1335.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1336.           if (pc)
  1337.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1338.           else
  1339.             sprintf(tempo,"%d",SInfo.stat_updated);
  1340.           inprogress->SetDlgItemText(IDC_i7 , tempo );
  1341.         }
  1342.         
  1343.         /*if (!parsing)*/
  1344.         {
  1345.           {
  1346.             int i;
  1347.             for(i=0;i<NStatsBuffer;i++) {
  1348.               if (StatsBuffer[i].sizetot>0) {
  1349.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1350.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1351.                 StatsBuffer[i].offset = (int) d;
  1352.               } else
  1353.                 StatsBuffer[i].offset = 0;
  1354.             }
  1355.           }
  1356.           
  1357.           if (!parsing)
  1358.             inprogress->m_sl0.SetRange(0,1000);
  1359.           inprogress->m_sl1.SetRange(0,1000);
  1360.           inprogress->m_sl2.SetRange(0,1000);
  1361.           inprogress->m_sl3.SetRange(0,1000);
  1362.           inprogress->m_sl4.SetRange(0,1000);
  1363.           inprogress->m_sl5.SetRange(0,1000);
  1364.           inprogress->m_sl6.SetRange(0,1000);
  1365.           inprogress->m_sl7.SetRange(0,1000);
  1366.           inprogress->m_sl8.SetRange(0,1000);
  1367.           inprogress->m_sl9.SetRange(0,1000);
  1368.           inprogress->m_sl10.SetRange(0,1000);
  1369.           inprogress->m_sl11.SetRange(0,1000);
  1370.           inprogress->m_sl12.SetRange(0,1000);
  1371.           inprogress->m_sl13.SetRange(0,1000);
  1372.           
  1373.           if (!parsing)
  1374.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1375.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1376.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1377.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1378.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1379.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1380.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1381.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1382.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1383.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1384.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1385.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1386.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1387.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1388.           
  1389.           // redraw en boucle
  1390.           {
  1391.             int i=0;
  1392.             if (parsing)
  1393.               i++;
  1394.             for( ; i<NStatsBuffer;i++) {
  1395.               inprogress->element[0][i]->SetWindowText(StatsBuffer[i].etat);
  1396.               inprogress->element[1][i]->SetWindowText(StatsBuffer[i].nom);
  1397.               inprogress->element[4][i]->SetWindowText(StatsBuffer[i].fichier);
  1398.               
  1399.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1400.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1401.                 if (!StatsBuffer[i].actived)
  1402.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1403.                 else
  1404.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1405.                 inprogress->element[3][i]->RedrawWindow();
  1406.               }
  1407.             }
  1408.           }
  1409.           //
  1410.         }
  1411.         /* else*/
  1412.         if (parsing) {  // parsing
  1413.           //
  1414.           inprogress->m_sl0.SetRange(0,100);
  1415.           inprogress->m_sl0.SetPos(parsing);
  1416.           inprogress->element[0][0]->SetWindowText(LANG(LANG_F14 /*"scanning","parcours"*/));
  1417.           inprogress->element[1][0]->SetWindowText(StatsBuffer[0].nom);
  1418.           inprogress->element[4][0]->SetWindowText("");
  1419.           //inprogress->element[0][1]->SetWindowText();
  1420.         }
  1421.         
  1422.       }
  1423.       {
  1424.         static char last_info[256]="";
  1425.         char info[256];
  1426.         if ((SInfo.stat_nsocket==-1)) {
  1427. #if USE_RAS
  1428.           if (!has_started)
  1429. #endif
  1430.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1431. #if USE_RAS
  1432.           else
  1433.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1434. #endif
  1435.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1436.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1437.           // inprogress->SetDlgItemText(IDC_nm1,_SN(ft));
  1438.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1439.             sprintf(info,"[%d s]",SInfo.stat_time);
  1440.           } else {
  1441.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1442.           }
  1443.         } else {
  1444.           if (icn) {  // minimisΘe
  1445.             sprintf(info,"[%s]",lnk);
  1446.           } else {
  1447.             sprintf(info,LANG(LANG_F18 /*"Mirror in progress [%s, %d bytes]","Miroir en cours [%s, %d octets]"*/),lnk,SInfo.stat_bytes);
  1448.           }
  1449.         }
  1450.         if (strcmp(info,last_info)) {       /* a changΘ */
  1451.           strcpy(last_info,info);           /* recopier */
  1452.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1453.             this_CSplitterFrame->IconChange(last_info);
  1454.           else
  1455.             this_app->GetMainWnd()->SetWindowText(last_info);
  1456.         }
  1457.       }  
  1458.       
  1459.       //inprogress->UpdateWindow();
  1460.     } else {
  1461.     }
  1462.   }
  1463.   INREDRAW_LOCKED=0;
  1464.   // xxc  SInfo.refresh=0;     // refresh ok!
  1465.   return 1;
  1466. }
  1467.  
  1468. /*
  1469. // refresh scan
  1470. int inprogress_refresh_scan() {
  1471. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1472. if (!SInfo.refresh) {
  1473. if (!inprogress->IsIconic()) {
  1474. int n;
  1475. // patch pour le scanning
  1476. if (n=hts_is_parsing()) {
  1477. strcpy(StatsBuffer[0].etat,"scanning");
  1478. inprogress->element[0][0]->SetWindowText("scanning");
  1479. StatsBuffer[0].sizetot=100;
  1480. StatsBuffer[0].size=n;
  1481. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1482. inprogress->m_sl0.SetPos(n);
  1483. //} else {
  1484. //  inprogress->element[0][0]->SetWindowText("...");
  1485. }
  1486. }
  1487. }
  1488. }
  1489. return 1;
  1490. }
  1491. */
  1492.  
  1493. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1494. char* __cdecl httrackengine_query(char* question) {
  1495.   strcpy(WIZ_question,question);
  1496.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1497.   return WIZ_reponse;
  1498. }
  1499.  
  1500. char* __cdecl httrackengine_query2(char* question) {
  1501.   strcpy(WIZ_question,question);
  1502.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1503.   return WIZ_reponse;
  1504. }
  1505.  
  1506. char* __cdecl httrackengine_query3(char* question) {
  1507.   strcpy(WIZ_question,question);
  1508.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1509.   return WIZ_reponse;
  1510. }
  1511.  
  1512. void __cdecl httrackengine_pause(char* lockfile) {
  1513.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1514.   remove(lockfile);
  1515. }
  1516.  
  1517. // modif RX 10/10/98 pour gestion des , et des tabs
  1518. char* connversion(char* chaine)
  1519. {
  1520.   for(int i=0;i < (int) strlen(chaine);i++) 
  1521.     if(chaine[i]=='\n') chaine[i]=' ';
  1522.     else if(chaine[i]==13) chaine[i]=' ';
  1523.     else if(chaine[i]==9) chaine[i]=' ';
  1524.     /*else if(chaine[i]==',') chaine[i]=' ';*/
  1525.     
  1526.     return chaine;
  1527. }
  1528.  
  1529.  
  1530. #if SHELL_MULTITHREAD
  1531. void __cdecl RunBackRobot(void* al_p) {
  1532.   int argc;
  1533.   char** argv;
  1534.   
  1535.   while((!inprogress) && (!termine)) Sleep(10);
  1536.   if (inprogress)
  1537.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1538.     //Sleep(100);
  1539.     
  1540.     Robot_params* al=(Robot_params*) al_p;
  1541.     argc = al->argc;
  1542.     argv = al->argv;
  1543.     HTTRACK_result=hts_main(argc,argv);
  1544.     
  1545.     termine=1;
  1546.     
  1547.     _endthread();
  1548. }
  1549. #endif
  1550.  
  1551. // modifs RX 10/10/98: gestion des ,
  1552. CString change(char* chaine,char c) {
  1553.   int comma=1; int first=1;
  1554.   CString chaine1;
  1555.   for(int i=0;i < (int) strlen(chaine);i++) {
  1556.     switch(chaine[i]) {
  1557.     case 10: case 13: case 9: case ' ': case ',':
  1558.       comma=1; 
  1559.       break;
  1560.     default:
  1561.       if (comma) {
  1562.         if (!first) chaine1 +=' ';
  1563.         else first=0; 
  1564.         chaine1  +=c; 
  1565.         comma=0;
  1566.       }
  1567.       chaine1 += chaine[i]; 
  1568.       break;
  1569.     }
  1570.   }
  1571.   return chaine1;
  1572. }
  1573.  
  1574.  
  1575. // Lancement
  1576. void lance(void) {
  1577.   char *argv[999];
  1578.   int argc=1;
  1579.   int g=0;
  1580.   int i =0;
  1581.   
  1582.   //
  1583.   if (fp_debug) {
  1584.     fprintf(fp_debug,"Building command line\r\n");
  1585.     fflush(fp_debug);
  1586.   }
  1587.   //
  1588.   LINE[0]='\0';
  1589.   strcpy(LINE,"-");
  1590.   if (choixdeb[0]!='W')
  1591.     strcat(LINE,"q");         // quiet
  1592.   
  1593.   if (choixdeb[0]=='/')
  1594.     strcat(LINE,"i");
  1595.   else if (choixdeb[0]!='!')
  1596.     strcat(LINE,choixdeb);
  1597.   // option de profondeur
  1598.   if(strcmp(OPTIONdepth,"")!=0) { 
  1599.     strcat(LINE,"r");
  1600.     strcat(LINE,OPTIONdepth);
  1601.   }
  1602.   if(strcmp(OPTIONextdepth,"")!=0) { 
  1603.     strcat(LINE,"%e");
  1604.     strcat(LINE,OPTIONextdepth);
  1605.   }
  1606.   if(strcmp(OPTIONcache,"")!=0) strcat(LINE,OPTIONcache);
  1607.   if(strcmp(OPTIONnorecatch,"")!=0) strcat(LINE,OPTIONnorecatch);
  1608.   if(strcmp(OPTIONtestall,"")!=0) strcat(LINE,OPTIONtestall);
  1609.   if(strcmp(OPTIONparseall,"")!=0) strcat(LINE,OPTIONparseall);
  1610.   if(strcmp(OPTIONlink,"")!=0) strcat(LINE,OPTIONlink);
  1611.   if(strcmp(OPTIONexternal,"")!=0) strcat(LINE,OPTIONexternal);
  1612.   if(strcmp(OPTIONnopurge,"")!=0) strcat(LINE,OPTIONnopurge);
  1613.   if(strcmp(OPTIONhidepwd,"")!=0) strcat(LINE,OPTIONhidepwd);
  1614.   if(strcmp(OPTIONhidequery,"")!=0) strcat(LINE,OPTIONhidequery);
  1615.   if(strcmp(OPTIONrobots,"")!=0) strcat(LINE,OPTIONrobots);
  1616.   if(strcmp(OPTIONcookies,"")!=0) strcat(LINE,OPTIONcookies);
  1617.   if(strcmp(OPTIONchecktype,"")!=0) strcat(LINE,OPTIONchecktype);
  1618.   if(strcmp(OPTIONparsejava,"")!=0) strcat(LINE,OPTIONparsejava);
  1619.   if(strcmp(OPTIONCache2,"")!=0) strcat(LINE,OPTIONCache2);
  1620.   if(strcmp(OPTIONlogtype,"")!=0) strcat(LINE,OPTIONlogtype);
  1621.   if (strlen(OPTIONhttp10)) strcat(LINE,OPTIONhttp10);
  1622.   if (strlen(OPTIONtoler)) strcat(LINE,OPTIONtoler);
  1623.   if (strlen(OPTIONupdhack)) strcat(LINE,OPTIONupdhack);
  1624.   
  1625.   // si get, ne pas faire
  1626.   if (strcmp(choixdeb,"g")!=0) {
  1627.     if(build[0]=='-') {
  1628.       strcat(LINE," ");
  1629.       strcat(LINE,build);
  1630.       strcat(LINE," -");
  1631.     } else if (strcmp(build,"")!=0) strcat(LINE,build);
  1632.   }
  1633.   strcat(LINE,OPTIONdos);
  1634.   strcat(LINE,OPTIONindex);
  1635.   strcat(LINE,OPTIONindex2);
  1636.   strcat(LINE,OPTIONhtmlfirst);
  1637.   strcat(LINE,filtre);
  1638.   strcat(LINE,OPTIONmax);
  1639.   strcat(LINE,OPTIONfrag);
  1640.   strcat(LINE,OPTIONmaxfile);
  1641.   strcat(LINE,OPTIONconn);
  1642.   strcat(LINE,OPTIONtime);
  1643.   strcat(LINE,OPTIONrate);
  1644.   strcat(LINE,OPTIONretry);
  1645.   strcat(LINE,OPTIONhostquit);
  1646.   strcat(LINE,OPTIONlog);
  1647.   strcat(LINE,OPTIONerrpage);
  1648.   //-->
  1649.   strcat(LINE,OPTIONwaittime);
  1650.   strcat(LINE,OPTIONmaxtime);
  1651.   strcat(LINE,OPTIONmaxrate);
  1652.   strcat(LINE,OPTIONmaxconn);
  1653.   strcat(LINE,OPTIONmaxlinks);
  1654.   strcat(LINE,"#f");  // flush
  1655.   
  1656.   if (strcmp(OPTIONuser,"")!=0) {strcat(LINE," ");strcat(LINE,"-F");strcat(LINE," ");strcat(LINE,OPTIONuser);}
  1657.   if (strcmp(OPTIONfooter,"")!=0) {strcat(LINE," ");strcat(LINE,"-%F");strcat(LINE," ");strcat(LINE,OPTIONfooter);}
  1658.   
  1659.   if ((int)strlen(OPTIONproxy)>0) {
  1660.     strcat(LINE," -P ");
  1661.     strcat(LINE,OPTIONproxy);
  1662.     strcat(LINE,":");
  1663.     strcat(LINE,OPTIONport);
  1664.   }
  1665.   
  1666.   if (strnotempty(LANGUAGE_ISO)) {
  1667.     strcat(LINE," -%l \"");
  1668.     strcat(LINE,LANGUAGE_ISO);
  1669.     if (strcmp(LANGUAGE_ISO,"en")!=0)
  1670.       strcat(LINE,", en");
  1671.     strcat(LINE,", *\"");
  1672.   }
  1673.   
  1674.   // mode spider, mettre aprΦs options
  1675.   if (choixdeb[0]=='!') {
  1676.     strcat(LINE," --testlinks");
  1677.   } else if (choixdeb[0]=='Y') {
  1678.     strcat(LINE," --mirrorlinks");
  1679.   }
  1680.   
  1681.   // URLs!!
  1682.   strcat(LINE," ");
  1683.   strcat(LINE,OPTIONurl);
  1684.   
  1685.   // file list
  1686.   if ((int) strlen(OPTIONfilelist)>0) {
  1687.     strcat(LINE," -%L \"");
  1688.     strcat(LINE,OPTIONfilelist);
  1689.     strcat(LINE,"\"");
  1690.   }
  1691.   
  1692.   // chemins
  1693.   if(strcmp(OPTIONpath,"")!=0) {
  1694.     strcat(LINE," ");
  1695.     strcat(LINE,"-O");
  1696.     strcat(LINE," ");
  1697.     strcat(LINE,OPTIONpath);
  1698.   }
  1699.   
  1700.   // buffer -> les + et -
  1701.   if(strcmp(buff_filtres,"")!=0) {
  1702.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1703.     strcat(LINE," ");
  1704.     strcat(LINE,buff_filtres );
  1705.   }
  1706.   
  1707.   // --assume
  1708.   if (strnotempty(buff_MIME)) {
  1709.     strcat(LINE," ");
  1710.     strcat(LINE,buff_MIME );
  1711.   }
  1712.   
  1713.   // ---
  1714.   
  1715.   //
  1716.   if (fp_debug) {
  1717.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1718.     fflush(fp_debug);
  1719.   }
  1720.   //
  1721.   // Θpurer cr,lf,tab - double espace -> espace
  1722.   {
  1723.     char *a;
  1724.     while(a=strchr(LINE,9)) *a=' ';
  1725.     while(a=strchr(LINE,10)) *a=' ';
  1726.     while(a=strchr(LINE,13)) *a=' ';
  1727.     /* Eviter a cause des noms longs
  1728.     while(a=strstr(LINE," - ")) {     // options isolΘes sans rien
  1729.     char tempo[65535]; tempo[0]='\0';
  1730.     strncat(tempo,LINE,(int) a - (int) LINE);
  1731.     strcat(tempo,a+2);
  1732.     strcpy(LINE,tempo);
  1733.     }
  1734.     while(a=strstr(LINE,"  ")) {
  1735.     char tempo[65535]; tempo[0]='\0';
  1736.     strncat(tempo,LINE,(int) a - (int) LINE);
  1737.     strcat(tempo,a+1);
  1738.     strcpy(LINE,tempo);
  1739.     }
  1740.     */
  1741.   }
  1742.   
  1743.   char LINE_back[65535];
  1744.   strcpy(LINE_back,LINE);
  1745.   
  1746.   // couper en morceaux
  1747.   {
  1748.     char* p=LINE;
  1749.     argv[0]="winhttrack";
  1750.     do {
  1751.       argv[argc++]=p;
  1752.       p=next_token(p,0);    // prochain token
  1753.       if (p) {
  1754.         *p=0;    // octet nul (tableau)
  1755.         p++;
  1756.       }            
  1757.     } while(p!=NULL);
  1758.   }
  1759.   
  1760.   //
  1761.   if (fp_debug) {
  1762.     fprintf(fp_debug,"Checking doit.log\r\n");
  1763.     fflush(fp_debug);
  1764.   }
  1765.   //
  1766.   // Ok, on lance!
  1767.   if(!termine) {
  1768.     int result=0;
  1769.     {
  1770.       char path_log[HTS_URLMAXSIZE*2];
  1771.       strcpy(path_log,CShellApp_app->end_path_complete);
  1772.       if (strlen(path_log)>0)
  1773.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1774.           strcat(path_log,"/");
  1775.         
  1776.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1777.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1778.         //if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dΘja un cache prΘcΘdent.. renommer
  1779.         if (fexist(fconcat(path_log,"hts-cache/new.ndx"))) {    // un cache est prΘsent
  1780.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1781.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1782.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1783.           if (fp) fclose(fp);
  1784.         }
  1785.         //}
  1786.     }
  1787.     
  1788.     
  1789.     // ---
  1790.     // LANCER LE MIROIR
  1791.     // ---
  1792.     //
  1793.     if (fp_debug) {
  1794.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1795.       fflush(fp_debug);
  1796.     }
  1797.     //
  1798. #if SHELL_MULTITHREAD
  1799.     Robot_params al;
  1800.     al.argc=argc;
  1801.     al.argv=argv;
  1802.     _beginthread( RunBackRobot     , 0, (void*) &al);
  1803.     //_beginthread( RefreshBackRobot , 0, NULL);
  1804.     
  1805.     //
  1806.     if (fp_debug) {
  1807.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1808.       fflush(fp_debug);
  1809.     }
  1810.     //
  1811.     // domodal du refresh
  1812.     /* XXC A SUPPRIMER */
  1813.     while(!termine) {
  1814.       Sleep(250);
  1815.     }
  1816.     //inprogress->DoModal();
  1817.     shell_terminated=1;
  1818.     //
  1819.     result=HTTRACK_result;
  1820.     termine=1;  
  1821.     //
  1822.     if (fp_debug) {
  1823.       fprintf(fp_debug,"Main dialog exited\r\n");
  1824.       fflush(fp_debug);
  1825.     }
  1826.     //
  1827.     
  1828.     // non multithread
  1829. #else
  1830. #error "Non supportΘ"
  1831. #endif
  1832.  
  1833.     /* Aborted mirror or finished? */
  1834.     {
  1835.       char path_log[HTS_URLMAXSIZE*2];
  1836.       strcpy(path_log,CShellApp_app->end_path_complete);
  1837.       if (strlen(path_log)>0)
  1838.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1839.           strcat(path_log,"/");
  1840.         if (soft_term_requested || termine_requested) {
  1841.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  1842.           if (fp)
  1843.             fclose(fp);
  1844.         } else
  1845.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  1846.     }
  1847.     
  1848.     //SetForegroundWindow();   // yop en premier plan!
  1849.     //
  1850.     if (fp_debug) {
  1851.       fprintf(fp_debug,"Displaying end dialog\r\n");
  1852.       fflush(fp_debug);
  1853.     }
  1854.     //
  1855.     /* New pannel */
  1856.     if (result) {      // erreur?
  1857.       strcpy(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  1858.       strcat(end_mirror_msg,"\"");
  1859.       strcat(end_mirror_msg,hts_errmsg());
  1860.       strcat(end_mirror_msg,"\"");
  1861.       strcat(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  1862.       strcat(end_mirror_msg,"\"");
  1863.       strcat(end_mirror_msg,LINE_back);
  1864.       strcat(end_mirror_msg,"\"");
  1865.       strcat(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  1866.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  1867.     } else {
  1868.       strcpy(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  1869.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  1870.       //        ShellExecute(0,"open",,"","",);
  1871.     }
  1872. #if USE_RAS
  1873.     // erreur ras
  1874.     if (connected == -1)
  1875.       if ((int) strlen(connected_err) > 0)
  1876.         strcpy(end_mirror_msg,connected_err);
  1877. #endif
  1878.       {
  1879.         char pathlog[HTS_URLMAXSIZE*2];
  1880.         strcpy(pathlog,dialog0->GetPath());
  1881.         Ciplog form;
  1882.         if (strlen(pathlog)>0)
  1883.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  1884.             strcat(pathlog,"/");
  1885.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  1886.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  1887.             strcat(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  1888.           }
  1889.       }
  1890.       //this_Cinfoend->m_infoend = msg;
  1891.       inprogress->SendMessage(WM_USER + 4);      // avertir
  1892.       if (fp_debug) {
  1893.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  1894.         fflush(fp_debug);
  1895.       }
  1896.       /*
  1897.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  1898.       // copie de onnewproject() de wid1::
  1899.       CWinApp* pApp = AfxGetApp();
  1900.       CString name = pApp->m_pszHelpFilePath;
  1901.       name=name.Left(name.GetLength()-4);
  1902.       name += ".EXE";
  1903.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  1904.       }
  1905.       */
  1906.       if (fp_debug) {
  1907.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  1908.         fflush(fp_debug);
  1909.       }
  1910.   }
  1911.   else {
  1912.   }
  1913.   
  1914. }
  1915.  
  1916. // int LANG_T(int);
  1917. // char* LANG(char* english,char* francais);
  1918.  
  1919.  
  1920. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  1921. void SetCombo(CWnd* _this,int id,char* lang_string) {
  1922.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  1923.   CString st=lang_string;
  1924.   st.TrimLeft(); st.TrimRight();
  1925.   if (combo) {
  1926.     st+="\n";         /* end */
  1927.     combo->ResetContent();
  1928.     while(st.GetLength()) {
  1929.       int pos=st.Find('\n');
  1930.       CString item=st.Left(pos);
  1931.       st=st.Mid(pos+1);
  1932.       item.TrimLeft(); item.TrimRight();
  1933.       if (item.GetLength())
  1934.         combo->AddString(item);
  1935.     }
  1936.   }
  1937. }
  1938.  
  1939.  
  1940. // Ecriture profiles
  1941. char* profile_code(char* from) {
  1942.   static char buff[65535];
  1943.   int i;
  1944.   int j;
  1945.   for(i=0,j=0;i<(int) strlen(from);i++) {
  1946.     switch(from[i]) {
  1947.     case '%': 
  1948.       buff[j++]='%';
  1949.       buff[j++]='%';
  1950.       break;
  1951.     case '=': 
  1952.       buff[j++]='%';
  1953.       buff[j++]='3';
  1954.       buff[j++]='d';
  1955.       break;
  1956.     case 13:
  1957.       buff[j++]='%';
  1958.       buff[j++]='0';
  1959.       buff[j++]='d';
  1960.       break;
  1961.     case 10:
  1962.       buff[j++]='%';
  1963.       buff[j++]='0';
  1964.       buff[j++]='a';
  1965.       break;
  1966.     case 9:
  1967.       buff[j++]='%';
  1968.       buff[j++]='0';
  1969.       buff[j++]='9';
  1970.       break;
  1971.     default:
  1972.       buff[j++]=from[i];
  1973.       break;
  1974.     }
  1975.   }
  1976.   buff[j++]='\0';
  1977.   return buff;
  1978. }
  1979. char* profile_decode(char* from) {
  1980.   static char buff[2048];
  1981.   int i;
  1982.   int j;
  1983.   for(i=0,j=0;j<(int) strlen(from);i++) {  // oui oui
  1984.     if (from[j]=='%') {
  1985.       if (from[j+1]=='%') {
  1986.         buff[i]='%';
  1987.         j+=2;
  1988.       } else {
  1989.         if (strncmp(from+j+1,"0d",2)==0)
  1990.           buff[i]=13;
  1991.         else if (strncmp(from+j+1,"0a",2)==0)
  1992.           buff[i]=10;
  1993.         else if (strncmp(from+j+1,"09",2)==0)
  1994.           buff[i]=9;
  1995.         else if (strncmp(from+j+1,"3d",2)==0)
  1996.           buff[i]='=';
  1997.         else
  1998.           buff[i]=' ';
  1999.         j+=3;
  2000.       }
  2001.     } else
  2002.       buff[i]=from[j++];
  2003.   }
  2004.   buff[i++]='\0';
  2005.   return buff;
  2006. }
  2007. //
  2008. // Ecriture/Lecture profiles
  2009. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2010.   if (path.IsEmpty()) {
  2011.     CWinApp* pApp = AfxGetApp();
  2012.     pApp->WriteProfileInt(dummy,name,value);
  2013.   } else if (path=="<mem>") {       // buffer
  2014.     tmpm.setInt(name,value);
  2015.     return 0;
  2016.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2017.     if (tmpf) {
  2018.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2019.     }
  2020.   } else {
  2021.     FILE* fp = fopen(path,"ab");
  2022.     if (fp) {
  2023.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2024.       /*
  2025.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2026.       */
  2027.       fclose(fp);
  2028.       return r;
  2029.     }
  2030.   }
  2031.   return 0;
  2032. }
  2033. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2034.   if (fp) {
  2035.     fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2036.   }
  2037.   return 0;
  2038. }
  2039. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2040.   if (path.IsEmpty()) {
  2041.     CWinApp* pApp = AfxGetApp();
  2042.     char *tempo;
  2043.     tempo=(char*) malloc(strlen(value)+1);
  2044.     if (tempo) {
  2045.       strcpy(tempo,value);
  2046.       pApp->WriteProfileString(dummy,name,profile_code(tempo));
  2047.     } else
  2048.       return -1;      // error
  2049.   } else if (path=="<mem>") {       // buffer
  2050.     tmpm.setString(name,value);
  2051.     return 0;
  2052.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2053.     if (tmpf) {
  2054.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2055.     }
  2056.   } else {
  2057.     FILE* fp = fopen(path,"ab");
  2058.     if (fp) {
  2059.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2060.       /*
  2061.       char *tempo;
  2062.       tempo=(char*) malloc(strlen(value)+1);
  2063.       if (tempo) {
  2064.       strcpy(tempo,value);
  2065.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2066.       fclose(fp);
  2067.       free(tempo);
  2068.       } else
  2069.       return -1;      // error
  2070.       */
  2071.       fclose(fp);
  2072.       return r;
  2073.     }
  2074.   }
  2075.   return 0;
  2076. }
  2077. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2078.   if (fp) {
  2079.     char *tempo;
  2080.     tempo=(char*) malloc(strlen(value)+1);
  2081.     if (tempo) {
  2082.       strcpy(tempo,value);
  2083.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2084.       free(tempo);
  2085.     } else
  2086.       return -1;      // error
  2087.   }
  2088.   return 0;
  2089. }
  2090. //
  2091. // lecture
  2092. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2093.   if (path.IsEmpty()) {
  2094.     CWinApp* pApp = AfxGetApp();
  2095.     return pApp->GetProfileInt(dummy,name,value);
  2096.   } else if (path=="<mem>") {       // buffer
  2097.     return tmpm.getInt(name,value);
  2098.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2099.     if (tmpf) {
  2100.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2101.     } else return value;
  2102.   } else {
  2103.     FILE* fp = fopen(path,"rb");
  2104.     if (fp) {
  2105.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2106.       /*
  2107.       char srch[256];
  2108.       sprintf(srch,"%s=",name);
  2109.       while(!feof(fp)) {
  2110.       char s[HTS_URLMAXSIZE*2];
  2111.       linput(fp,s,1020);
  2112.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2113.       int val;
  2114.       if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2115.       return val;
  2116.       else
  2117.       return value;
  2118.       }
  2119.       }
  2120.       fclose(fp);
  2121.       return value;
  2122.       */
  2123.       fclose(fp);
  2124.       return r;
  2125.     } else return value;
  2126.   }
  2127. }
  2128. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2129.   if (fp) {
  2130.     char srch[256];
  2131.     fseek(fp,0,SEEK_SET);
  2132.     sprintf(srch,"%s=",name);
  2133.     while(!feof(fp)) {
  2134.       char s[2048]; s[0]='\0';
  2135.       linput(fp,s,2000);
  2136.       if (strlen(s)==0)     // EOF
  2137.         return value;
  2138.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2139.         int val;
  2140.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2141.           return val;
  2142.         else
  2143.           return value;
  2144.       }
  2145.     }
  2146.     return value;
  2147.   } else return value;
  2148. }
  2149. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2150.   if (path.IsEmpty()) {
  2151.     CWinApp* pApp = AfxGetApp();
  2152.     char tempo[32768];
  2153.     char value_default[32768];
  2154.     strcpy(value_default,value);
  2155.     strcpy(tempo,pApp->GetProfileString(dummy,name,profile_code(value_default)));
  2156.     return profile_decode(tempo);
  2157.   } else if (path=="<mem>") {       // buffer
  2158.     return tmpm.getString(name,value);
  2159.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2160.     if (tmpf) {
  2161.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2162.     } else return value;
  2163.   } else {
  2164.     FILE* fp = fopen(path,"rb");
  2165.     if (fp) {
  2166.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2167.       /*
  2168.       char srch[256];
  2169.       sprintf(srch,"%s",name);
  2170.       strcat(srch,"=");
  2171.       while(!feof(fp)) {
  2172.       char s[32768];
  2173.       linput(fp,s,32000);
  2174.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2175.       return profile_decode(s+strlen(srch));
  2176.       }
  2177.       }
  2178.       fclose(fp);
  2179.       return value;
  2180.       */
  2181.       fclose(fp);
  2182.       return st;
  2183.     } else return value;
  2184.   }
  2185. }
  2186. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2187.   if (fp) {
  2188.     char srch[256];
  2189.     fseek(fp,0,SEEK_SET);
  2190.     sprintf(srch,"%s",name);
  2191.     strcat(srch,"=");
  2192.     while(!feof(fp)) {
  2193.       char s[32768]; s[0]='\0';
  2194.       linput(fp,s,32000);
  2195.       if (strlen(s)==0)     // EOF
  2196.         return value;
  2197.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2198.         return profile_decode(s+strlen(srch));
  2199.       }
  2200.     }
  2201.     return value;
  2202.   } else return value;
  2203. }
  2204.  
  2205. //
  2206. // Get_profile et Write_profile eux mΩmes
  2207. //
  2208. // path="" -> Θcrire dans la base (default)
  2209. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2210. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2211. // path="<null>" -> lire default (illΘgal en Θcriture)
  2212. void Write_profile(CString path,int load_path) {
  2213.   CWaitCursor wait;
  2214.   CString strSection       = "OptionsValues";
  2215.   CString st;
  2216.   int n;
  2217.   
  2218.   // Fichier tempo ou fichier?
  2219.   if (path=="<tmp>") {     // fichier temporaire
  2220.     if (tmpf)
  2221.       fclose(tmpf);
  2222.     tmpf=tmpfile();
  2223.     if (!tmpf)
  2224.       return;
  2225.   } else if (path=="<mem>") {     // buffer temporaire
  2226.     tmpm.deleteAll();
  2227.   } else if (!(path.IsEmpty())) {
  2228.     FILE *fp=fopen(path,"wb");
  2229.     if (fp) 
  2230.       fclose(fp);
  2231.   }
  2232.   
  2233.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2234.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2235.     // checkboxes
  2236.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2237.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2238.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2239.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2240.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2241.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2242.     MyWriteProfileInt(path,strSection, "Dos",maintab->m_option2.m_dos);
  2243.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2244.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2245.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2246.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2247.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2248.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2249.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2250.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2251.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2252.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2253.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2254.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2255.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2256.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2257.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2258.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2259.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2260.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2261.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2262.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2263.     
  2264.     // menus
  2265.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2266.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2267.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2268.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2269.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2270.     
  2271.     // champs
  2272.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2273.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2274.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2275.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2276.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2277.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2278.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2279.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2280.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2281.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2282.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2283.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2284.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2285.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2286.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2287.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2288.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2289.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2290.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2291.     
  2292.     // 11
  2293.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2294.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2295.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2296.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2297.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2298.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2299.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2300.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2301.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2302.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2303.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2304.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2305.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2306.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2307.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2308.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);    
  2309.   } else {
  2310.     // checkboxes
  2311.     // 1
  2312.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2313.     MyWriteProfileInt(path,strSection,"Near", n);
  2314.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2315.     MyWriteProfileInt(path,strSection,"Test", n);
  2316.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2317.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2318.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2319.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2320.     // 2
  2321.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2322.     MyWriteProfileInt(path,strSection,"Cache", n);
  2323.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2324.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2325.     n=maintab->m_option2.IsDlgButtonChecked(IDC_dos);
  2326.     MyWriteProfileInt(path,strSection,"Dos", n);
  2327.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2328.     MyWriteProfileInt(path,strSection,"Index", n);
  2329.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2330.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2331.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2332.     MyWriteProfileInt(path,strSection,"Log", n);
  2333.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2334.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2335.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2336.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2337.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2338.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2339.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2340.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2341.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2342.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2343.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2344.       MyWriteProfileInt(path,strSection, "Build", n);
  2345.     st = maintab->m_option2.Bopt.m_BuildString;
  2346.     if (st.GetLength()>0)
  2347.       MyWriteProfileString(path,strSection, "BuildString",st);
  2348.     // 3
  2349.     // menus
  2350.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2351.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2352.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2353.       MyWriteProfileInt(path,strSection, "Travel", n);
  2354.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2355.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2356.     //
  2357.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2358.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2359.     // 4
  2360.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2361.     MyWriteProfileString(path,strSection, "Sockets", st);
  2362.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2363.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2364.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2365.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2366.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2367.     MyWriteProfileString(path,strSection, "Retry", st);
  2368.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2369.     MyWriteProfileString(path,strSection, "RateOut", st);
  2370.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2371.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2372.     // 5
  2373.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2374.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2375.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2376.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2377.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2378.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2379.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2380.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2381.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2382.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2383.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2384.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2385.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2386.     MyWriteProfileString(path,strSection,"Depth",st);
  2387.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2388.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2389.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2390.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2391.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2392.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2393.     // 6
  2394.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2395.     MyWriteProfileString(path,strSection, "UserID", st);
  2396.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2397.     MyWriteProfileString(path,strSection, "Footer", st);
  2398.     // 7
  2399.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2400.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2401.     // 8
  2402.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2403.     MyWriteProfileString(path,strSection, "Cookies", st);
  2404.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2405.     MyWriteProfileString(path,strSection, "CheckType", st);
  2406.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2407.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2408.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2409.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2410.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2411.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2412.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2413.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2414.     // 9
  2415.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2416.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2417.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2418.     MyWriteProfileString(path,strSection, "LogType", st);
  2419.     // 10
  2420.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2421.     MyWriteProfileString(path,strSection,"Proxy",st);
  2422.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2423.     MyWriteProfileString(path,strSection,"Port",st);
  2424.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2425.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2426.     
  2427.     // 11
  2428.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2429.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2430.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2431.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2432.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2433.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2434.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2435.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2436.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2437.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2438.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2439.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2440.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2441.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2442.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2443.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2444.   }
  2445.   // liens, jokers etc. si mirror merge
  2446.   if (!(path.IsEmpty())) {
  2447.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2448.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2449.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2450.       if (dialog1->m_todo >= 0)
  2451.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2452.       //
  2453.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2454.       
  2455.       //if (load_path) {
  2456.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2457.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2458.       //}
  2459.     } else {
  2460.       //dialog1->GetDlgItemText(IDC_depth,st);
  2461.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2462.       dialog1->GetDlgItemText(IDC_URL,st);
  2463.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2464.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2465.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2466.       //
  2467.       dialog1->GetDlgItemText(IDC_filelist,st);
  2468.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2469.       //
  2470.       //if (load_path) {
  2471.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2472.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2473.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2474.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2475.       //}
  2476.     }
  2477.   }
  2478. }
  2479. // path="" -> lire dans la base (default)
  2480. //if not exist: do not load anything but patches projname&co
  2481. void Read_profile(CString path,int load_path) {
  2482.   CWaitCursor wait;
  2483.   CString strSection       = "OptionsValues";
  2484.   CString st;
  2485.   
  2486.   // VΘrification <tmp>
  2487.   if (path=="<tmp>") {     // fichier temporaire
  2488.     if (!tmpf)
  2489.       return;
  2490.     else
  2491.       fflush(tmpf);
  2492.   } else if (path=="<null>") {     // options par dΘfaut
  2493.     path="<mem>";
  2494.     tmpm.deleteAll();              // effacer
  2495.   } else {
  2496.     int pos=path.ReverseFind('\\');
  2497.     if (pos>=0) {
  2498.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2499.       pos=dir.ReverseFind('\\');
  2500.       if (pos>=0) {
  2501.         dir=dir.Left(pos);                  // enlever hts-cache
  2502.         pos=dir.ReverseFind('\\');
  2503.         if (pos>=0) {
  2504.           dialog0->m_projname=dir.Mid(pos+1);
  2505.           dialog0->m_projpath=dir.Left(pos);
  2506.           /*
  2507.           if (this_CWizTab)
  2508.           this_CWizTab->SetActivePage(2);     // page 3
  2509.           */
  2510.         }
  2511.       }
  2512.     }
  2513.   }
  2514.   
  2515.   // checkboxes
  2516.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2517.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2518.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2519.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2520.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2521.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2522.   maintab->m_option2.m_dos       = MyGetProfileInt(path,strSection, "Dos",0);
  2523.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2524.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2525.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2526.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2527.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2528.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2529.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2530.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2531.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2532.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2533.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2534.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2535.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2536.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2537.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2538.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2539.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2540.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2541.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2542.   
  2543.   // menus
  2544.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2545.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2546.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2547.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2548.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2549.   
  2550.   // champs
  2551.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2552.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2553.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2554.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2555.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2556.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2557.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2558.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2559.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2560.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2561.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2562.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate");
  2563.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2564.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2565.   
  2566.   // 7
  2567.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2568.   
  2569.   // 10
  2570.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2571.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2572.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2573.   //
  2574.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2575.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2576.   
  2577.   // 11
  2578.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1");
  2579.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2580.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2581.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2582.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2583.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2584.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2585.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2586.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1");
  2587.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2588.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2589.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2590.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2591.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2592.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2593.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2594.   
  2595.   
  2596.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2597.   //strcpy(buff_filtres,st);
  2598.   
  2599.   // liens, jokers etc. si mirror merge
  2600.   if (!(path.IsEmpty())) {
  2601.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2602.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2603.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2604.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2605.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2606.       /*
  2607.       if (load_path) {
  2608.       CString st;
  2609.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2610.       if (st != "")
  2611.       dialog1->m_pathlog = st;
  2612.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2613.       if (st != "")
  2614.       dialog1->m_pathmir = st;
  2615.       }
  2616.       */
  2617.     } else {
  2618.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2619.       //dialog1->SetDlgItemText(IDC_depth,st);
  2620.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2621.       dialog1->SetDlgItemText(IDC_URL,st);
  2622.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2623.       dialog1->m_ctl_todo.SetCurSel(n);
  2624.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2625.       dialog1->SetDlgItemText(IDC_filelist,st);
  2626.       /*
  2627.       if (load_path) {
  2628.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2629.       if (st != "")
  2630.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2631.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2632.       if (st != "")
  2633.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2634.       }
  2635.       */
  2636.       dialog1->Refresh();
  2637.     }
  2638.   }
  2639.   
  2640. }
  2641.  
  2642. // Initialisation du RAS
  2643. void InitRAS() {
  2644. #if USE_RAS
  2645.   if (!LibRas) {
  2646.     LibRas=new CDynamicRAS();
  2647.     if (LibRas->IsRASLoaded()) 
  2648.       LibRasUse=1;
  2649.     else
  2650.       LibRasUse=0;
  2651.   }
  2652. #endif
  2653. }
  2654.  
  2655. // Reconstruire index gΘnΘral!
  2656. void Build_TopIndex(BOOL check_empty) {
  2657.   CWaitCursor wait;
  2658.  
  2659.   // templates html
  2660.   char* toptemplate_header=readfile_or("httrack/topindex-header.html",HTS_INDEX_HEADER);
  2661.   char* toptemplate_body=readfile_or("httrack/topindex-body.html",HTS_INDEX_BODY);
  2662.   char* toptemplate_footer=readfile_or("httrack/topindex-footer.html",HTS_INDEX_FOOTER);
  2663.   
  2664.   if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2665.     
  2666.     char path[HTS_URLMAXSIZE*2];
  2667.     strcpy(path,CShellApp_app->end_path);
  2668.     
  2669.     FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2670.     if (fpo) {
  2671.       verif_backblue(path);    // gΘnΘrer gif
  2672.       //
  2673.       // Header
  2674.       fprintf(fpo,toptemplate_header,
  2675.         "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2676.         );
  2677.       // chargement de la liste
  2678.       WIN32_FIND_DATA find;
  2679.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2680.       if (h != INVALID_HANDLE_VALUE) {
  2681.         CString to_delete="";
  2682.         do {
  2683.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2684.             if (strcmp(find.cFileName,".."))
  2685.               if (strcmp(find.cFileName,"."))
  2686.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2687.                   int r;
  2688.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2689.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2690.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2691.                   } else {      /* non vide */
  2692.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2693.                     strcpy(iname,CShellApp_app->end_path);
  2694.                     strcat(iname,find.cFileName);
  2695.                     strcat(iname,"\\");
  2696.                     strcpy(iname2,iname);
  2697.                     strcat(iname,"index.html");
  2698.                     strcat(iname2,"\\hts-cache\\winprofile.ini");
  2699.                     if (fexist(iname)) {
  2700.                       char hname[HTS_URLMAXSIZE*2];
  2701.                       strcpy(hname,find.cFileName);
  2702.                       escape_check_url(hname);
  2703.                       // Body
  2704.                       fprintf(fpo,toptemplate_body,
  2705.                         hname,
  2706.                         find.cFileName
  2707.                         );
  2708.                     }
  2709.                     
  2710.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2711.                       // vΘrifier existence de .whtt
  2712.                       strcpy(iname,CShellApp_app->end_path);
  2713.                       strcat(iname,find.cFileName);
  2714.                       strcat(iname,".whtt");
  2715.                       if (!fexist(iname)) {
  2716.                         FILE* fp=fopen(iname,"wb");
  2717.                         if (fp) fclose(fp);
  2718.                       }
  2719.                       
  2720.                     }
  2721.                   }
  2722.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2723.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2724.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2725.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2726.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2727.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2728.                       remove(iname);
  2729.                     }
  2730.                   }
  2731.                 }
  2732.         } while(FindNextFile(h,&find));
  2733.         FindClose(h);
  2734.         if (check_empty) {
  2735.           while(to_delete.GetLength()>0) {
  2736.             int pos=to_delete.Find('\n');
  2737.             if (pos) {
  2738.               CString path=to_delete.Left(pos);
  2739.               to_delete=to_delete.Mid(pos+1);
  2740.               CString str;
  2741.               str.Format(LANG_DELETEEMPTYCONF,path);
  2742.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2743.                 /* Θliminer au besoin le .whtt */
  2744.                 DeleteFile(path+".whtt");
  2745.                 if (!RemoveEmptyDir(path))
  2746.                   AfxMessageBox(LANG_ERRORDEL);
  2747.               }
  2748.             } else
  2749.               to_delete="";
  2750.           }
  2751.         }
  2752.       }
  2753.       // Footer
  2754.       fprintf(fpo,toptemplate_footer,
  2755.         "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2756.         );
  2757.       fclose(fpo);
  2758.     }
  2759.     
  2760.   }
  2761.   
  2762.   if (toptemplate_header)
  2763.     freet(toptemplate_header);
  2764.   if (toptemplate_body)
  2765.     freet(toptemplate_body);
  2766.   if (toptemplate_footer)
  2767.     freet(toptemplate_footer);
  2768. }
  2769.  
  2770. /*
  2771. -1 : error
  2772. 0 : directory is empty
  2773. 1 : empty directories inside
  2774. 2 : empty files inside
  2775. 3 : 1 + 2
  2776. 4 : not empty
  2777. */
  2778. int CheckDirInfo(CString path) {
  2779.   CWaitCursor wait;
  2780.   
  2781.   if (path.Right(1)!="\\")
  2782.     path+="\\";
  2783.   
  2784.   // Pour FindFirstFile/FindNextFile
  2785.   WIN32_FIND_DATA find;
  2786.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2787.   
  2788.   // accessible
  2789.   if (h!=INVALID_HANDLE_VALUE) {
  2790.     int return_code=0;
  2791.     do {
  2792.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2793.         if (strcmp(find.cFileName,"..")) {
  2794.           if (strcmp(find.cFileName,".")) {
  2795.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2796.               return_code|=1;
  2797.               int r=CheckDirInfo(path+find.cFileName);
  2798.               if (r==4)
  2799.                 return_code=4;
  2800.               else
  2801.                 return_code|=r;
  2802.             } else {
  2803.               return_code|=2;
  2804.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2805.                 return_code=4;
  2806.             }
  2807.           }
  2808.         }
  2809.       }
  2810.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2811.     FindClose(h);
  2812.     return return_code;
  2813.   } else
  2814.     return -1;
  2815. }
  2816.  
  2817. /*
  2818. Remove Empty Dir
  2819. */
  2820. BOOL RemoveEmptyDir(CString path) {
  2821.   CWaitCursor wait;
  2822.   
  2823.   SetCurrentDirectory("C:\\");
  2824.   
  2825.   if (path.Right(1)!="\\")
  2826.     path+="\\";
  2827.   
  2828.   // Pour FindFirstFile/FindNextFile
  2829.   WIN32_FIND_DATA find;
  2830.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2831.   
  2832.   // accessible
  2833.   if (h!=INVALID_HANDLE_VALUE) {
  2834.     do {
  2835.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2836.         if (strcmp(find.cFileName,"..")) {
  2837.           if (strcmp(find.cFileName,".")) {
  2838.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2839.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2840.                 FindClose(h);
  2841.                 return 0;
  2842.               }
  2843.             } else {
  2844.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2845.                 if (!DeleteFile(path+find.cFileName)) {
  2846.                   FindClose(h);
  2847.                   return 0;
  2848.                 }
  2849.             }
  2850.           }
  2851.         }
  2852.       }
  2853.     } while(FindNextFile(h,&find));
  2854.     FindClose(h);
  2855.     
  2856.     SetCurrentDirectory("C:\\");
  2857.     return RemoveDirectory(path.Left(path.GetLength()-1));
  2858.   } else
  2859.     return 0;
  2860.   return TRUE;
  2861. }
  2862.